package com.stenio.fancat.controller.shop;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.domain.shop.FcVenderImage;
import com.stenio.fancat.service.shop.VenderImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author liuan
 * @create 2019-01-16 15:00
 */

@RestController
@RequestMapping("vender/image")
public class VenderImageComtroller {

    @Autowired
    private VenderImageService venderImageService;

    /**
     * 上传图片
     * @param multipartFile
     * @return
     */
    @PostMapping("upload")
    @ResponseBody
    public Result<FcVenderImage> upload(@RequestParam(name = "file") MultipartFile multipartFile){
        Result<FcVenderImage> result = new Result();
        result.setData(venderImageService.saveImage(multipartFile));
        return result;
    }

    @GetMapping("{vId}")
    @ResponseBody
    public Result<List<FcVenderImage>> selectByType(@PathVariable Integer vId){
        Result<List<FcVenderImage>> result = new Result();
        FcVenderImage venderImage = new FcVenderImage();
        venderImage.setVenderId(vId);
        result.setData(venderImageService.selectByType(venderImage));
        return result;
    }

}
